#include <stdio.h>
#include <string.h>
#include <linux/types.h>


int test1()
{
	char string[10];
	char *str = "0123456789";
	
	strcpy(string, str);	// overflow
	
	return 0;
}

void test2()
{
	char string[10], str1[10];
	int i;
	
	for (i = 0; i < 10; i++)
		str1[i] = 'a';	// buneng jieshu, 
		
	strcpy(string, str1);	// copy zijie shu bu queding.   strcpy yi '\0' jieshu.
}

void test3(char *str)
{
	char string[10];
	
	if (strlen(str) <= 10)	// modify < 10
		strcpy(string, str);
}

struct aa
{
    int ab;
    int ac;
    int ad;
};

int main()
{
    char buff[32] = "xiaozhi";
    struct aa a = {.ab = 123, .ac = 456, .ad = 789};
    int i = 0;
    char ai = 0;

    printf("buff len:%ld %ld\n", sizeof(buff), strlen(buff));

    memset(buff, 0, 32);
    memcpy(buff, &a, sizeof(a));
    for (i = 0; i < 32; i++) {
        printf("buff:0x%x\n", buff[i]&0xff);
    }

    memset(buff, 0, 32);
    ai = 255;
    memcpy(buff, &ai, sizeof(ai));
    for (i = 0; i < 4; i++) {
        printf("ibuff:0x%x\n", buff[i]&0xff);
    }

	test1();
	test2();
	test3("0123456789");
}
